﻿<script type="text/javascript">
    $(document).ready(function () {
        $('.date').each(function () {
            $(this).datepicker({ showAnim: 'slide' });
        });
    });
</script>

<form method="post" action="/Defect/SubmitDefect">
    <fieldset>
        <legend>Defect</legend>

        @{List<CreateDefect.Models.DefectField> fields = ViewBag.Fields;}
        <ul class="newspaper">
            @foreach (var a in fields)
            {               
                if (a.DataType == "char" && !a.ColumnName.Contains("DESCRIPTION") && !a.ColumnName.Contains("COMMENT"))
                {
                    <li>
                        @Html.Label(a.DisplayName)
                        @if (a.Fields == null) { @Html.TextBox(a.DisplayName, "") }
                        else
                        {
                            List<SelectListItem> items = new List<SelectListItem>() { new SelectListItem() { Selected = true, Text="", Value="0" } };
                            foreach(string s in a.Fields)
                            {
                                items.Add(new SelectListItem() { Selected = false, Text = s });
                            }
                            
                            @Html.DropDownList(a.DisplayName, items, new { style="height:31px; width:310px;" })
                        }
                        @Html.ValidationMessage(a.DisplayName, a.DisplayName + " is a required field.")
                    </li>
                }
                else if (a.DataType == "DATE")
                {
                    <li>
                        @Html.Label(a.DisplayName)
                        @Html.TextBox(a.DisplayName, "", new { @class = "date" })
                        @Html.ValidationMessage(a.DisplayName, "Date format incorrect.",
                        new { ApplyFormatInEditMode = true, DataFormatString = "{0:dd MMM yyyy}" })
                    </li>
                }
            }
        </ul>
        <hr />
        <ul class="two-columns clearfix">
            @foreach (var a in fields)
            {
                if (a.ColumnName.Contains("DESCRIPTION") || a.ColumnName.Contains("COMMENT"))
                {
                    <li>
                        @Html.Label(a.DisplayName);
                        @Html.TextArea(a.DisplayName);
                        @Html.ValidationMessage(a.DisplayName, a.DisplayName + " is a required field.");
                    </li>
                }
            }
        </ul>
        <input type="submit" value="Create" id="submit_Button" />
    </fieldset>
</form>
